package com.herench.bs.handler;

import com.herench.bs.agent.IOutpatientClinicAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.dao.IClinicAppointmentRecordDao;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.Map;

/**
 * cleverClinic
 * com.herench.bs.handler
 *
 * @author wangwenkai
 * @date 2017/11/12/23:16
 */
@Component
@Handler(code = "102114" ,name="诊间支付撤销")
public class CanceleClinicChargePaymentInsuranceHandler extends AbstractMessageHandler {

    @Autowired
    private IClinicAppointmentRecordDao iClinicAppointmentRecordDao;

    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        String recordId = requestMessage.getArgsPropertyStringValue("recordId");
        Assert.notNull(recordId, "recordId 不可为空！");
        String patientId = requestMessage.getArgsPropertyStringValue("patientId");
        Assert.notNull(patientId, "patientId 不可为空！");
        String paySeq = requestMessage.getArgsPropertyStringValue("paySeq");
        Assert.notNull(paySeq, "paySeq 不可为空！");
        Map<String, Object> res = new HashMap<>(16);
        IOutpatientClinicAgent outpatientClinicAgent = getCleverClinicContext().getApplicationContext().getBean(IOutpatientClinicAgent.class);
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);
        res = outpatientClinicAgent.canceleClinicChargePaymentInsurance(channelCode, hospitalCode, recordId, patientId, paySeq);
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage, res);
        return responseMessage;
    }
}
